package com.hsmw.api.controller.driver;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.hsmw.api.service.HsmwBanDriverService;
import com.hsmw.api.vo.DriverInfoDTO;
import com.htn.common.core.base.DataResponse;
import com.htn.common.core.constant.CommonConstants;
import com.htn.common.core.utils.StringUtils;
import com.hsmw.domain.HsmwBanDriver;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.hsmw.common.base.BaseController;

import java.util.List;

/**
 * <p>
 * 封禁司机 前端控制器
 * </p>
 *
 * @author 许昌
 * @since 2021-08-30
 */
@Api(tags = "封禁司机")
@RestController
@RequestMapping("/hsmw/ban/driver")
public class HsmwBanDriverController extends BaseController<HsmwBanDriverService, HsmwBanDriver> {



    @Autowired
    private HsmwBanDriverService hsmwBanDriverService;


    /**
     *  新增或修改信息
     * @param hsmwBanDrivers
     * @return
     */
    @ApiOperation(value = "封禁司机 新增 修改 信息", notes = "封禁司机 新增 修改 信息", produces = "application/json")
    @PostMapping("/saveOrUpdateBanDriver")
    public DataResponse saveOrUpdateBanDriver(@RequestBody List<HsmwBanDriver> hsmwBanDrivers){


        return hsmwBanDriverService.saveOrUpdateBanDriver(hsmwBanDrivers);
    }

    @ApiOperation(value = "司机查询封禁状态", notes = "司机查询封禁状态", produces = "application/json")
    @ApiImplicitParam(name = "id",value = "司机id",dataType = "String")
    @PostMapping("/findBanDriverById")
    public DataResponse findBanDriverById(String id){
        HsmwBanDriver one = hsmwBanDriverService.getOne(new LambdaQueryWrapper<HsmwBanDriver>().eq(HsmwBanDriver::getDriverId, id).eq(HsmwBanDriver::getStatus, "1").orderByDesc(HsmwBanDriver::getCreateTime).last("LIMIT 1"));
        return new DataResponse(one);
    }


    @ApiOperation(value = "根据订单id查询司机信息", notes = "根据订单id查询司机信息", produces = "application/json")
    @ApiImplicitParam(name = "id",value = "订单id",dataType = "String")
    @PostMapping("/findDriverListByOrderId")
    public DataResponse findDriverListByOrderId(String id){
        if(StringUtils.isBlank(id)){
            return new DataResponse(CommonConstants.ResponseStatus.FAIL,"传递参数不可为空");
        }
        List<DriverInfoDTO> driverInfoDTO = hsmwBanDriverService.findDriverListByOrderId(id);
        return new DataResponse(driverInfoDTO);
    }







}

